package com.panda.rentHouse.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.panda.common.service.BaseServiceImpl;
import com.panda.common.util.JwtUtil;
import com.panda.rentHouse.dao.UserDao;
import com.panda.rentHouse.pojo.User;

@Service
@Transactional
public class UserServiceImpl extends BaseServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;
	
	@Override
	public List<User> findAll() throws Exception {
		return userDao.findAll();
	}

	@Override
	public Map<String, Object> loginCheck(String name, String password) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		User u = userDao.findByNameAndPassword(name, password);
		if(u!=null) {
			System.out.println(u);
			String userInfo = u.getId() + "|" + u.getName() + "|" + u.getPassword();
			String ETtoken = JwtUtil.createToken(userInfo, new Date().getTime());
			result.put("ETtoken", ETtoken);
		}
		return result;
	}

}
